﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace NGinnBPM.Services.Scripting.BooScript
{
    /// <summary>
    /// 
    /// </summary>
    class ScriptedClassGenerator
    {
        private TextWriter _out;

        public ScriptedClassGenerator(TextWriter output)
        {
            _out = output;
        }

        public void AddImportNamespace(string name)
        {
            _out.WriteLine("import {0}", name);
        }

        public void StartClass(string name, string baseClass)
        {
            _out.WriteLine("class {0} ({1}):", name, baseClass);
            _out.WriteLine("def Initialize():");
        }

        public void AddExpression(string key, string expression)
        {
            _out.WriteLine("add_expression \"{0}\":", key);
            if (expression.IndexOf("return ") >= 0)
                _out.WriteLine("{0}", expression);
            else
                _out.WriteLine("return ({0})", expression);
            _out.WriteLine("end");
        }

        public void AddCodeBlock(string key, string code)
        {
            _out.WriteLine("add_action \"{0}\":", key);
            _out.WriteLine(code);
            _out.WriteLine("end");
        }

        public void EndClass()
        {
            _out.WriteLine("end");
            _out.WriteLine("end");
        }
    }
}
